/************************************************************
* Copyright (C), 2010-2050, Tencent.
* 模块名    :
* 实现功能  :
* 备注      :

* 修改记录  :
* 日 期             修改人              修改内容
  2011.07.26         jasonpeng              创建
***********************************************************/
#include <stdlib.h>
#include <sstream>
#include "app_platform/cntl_info.h"
#include "app_platform/db_operator2.h"
#include "app_platform/res_factory.h"

#include "c2cplatform/component/dal/dal_set.h"
#include "c2cent/storage/resultset.h"

#include "c2cplatform/library/xml/xml_cfg_loader.h"
#include "libc2c/c2c_errno_define.h"

#include "logservice/logger.h"
#include "c2cent/library/log/CWWLog2.h"
#include "c2cent/library/log/CWTimeElf2.h"
#include "c2cplatform/component/configcenter/config_client_for_daemon.h"

#include "b2b2c_define.h"
#include "b2b2c_errno_define.h"
#include "b2b2c/comm/item_utils.h"
#include "cooperator_db_operator.h"

using namespace c2cent::library::wwlog;
using namespace c2cent::storage;
using namespace c2cplatform::component::dal;

using namespace b2b2c::comm;
using namespace item::cooperator::db;
using namespace b2b2c::cooperator::ddo;

#define DB_ROLE_NAME_COOPERATOR             "b2b2c_cooperator"
#define DB_ROLE_NAME_SELLER	                "b2b2c_seller"
#define TABLE_NAME_COOPERATOR               "t_cooperator_"
#define TABLE_NAME_COOPERATOR_LICENSE       "t_cooperator_license_"
#define TABLE_NAME_COOPERATOR_SUBACCOUNT    "t_cooperator_subaccount_"
#define TABLE_NAME_MONITOR_MODEL			"t_monitor_model_"


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//dal数据库连接
#define CONNECT_WITH_DAL(CmdId, CooperatorId, RoleName, TableName, UseSetId) \
    pIDB = CDAL_SET->GetDBOperator(CmdId, CooperatorId, RoleName, TableName, UseSetId);\
    if(pIDB == NULL)\
    {\
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "CDAL_SET->GetDBOperator() failed, CmdId:%u CooperatorId:%u \
                        RoleName:%s TableName:%s UseSetId:%u ErrMsg:%s", \
                        CmdId , CooperatorId, RoleName.c_str(), TableName.c_str(), UseSetId, CDAL_SET->getLastErrMsg()); \
        return ERR_B2B2C_DBSTORAGE_DBOPR;\
    }\
    oStorage.SetDBOperator(pIDB);

//过程中改变dal数据库连接
#define CHANGE_CONNECT_WITH_DAL(CmdId, CooperatorId, RoleName, TableName, UseSetId) \
    pIDB = CDAL_SET->GetDBOperator(CmdId, CooperatorId, RoleName, TableName, UseSetId);\
    if(pIDB == NULL)\
    {\
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "CDAL_SET->GetDBOperator() failed, CmdId:%u CooperatorId:%u RoleName:%s TableName:%s UseSetId:%u ErrMsg:%s", \
                            CmdId , CooperatorId, RoleName.c_str(), TableName.c_str(), UseSetId, CDAL_SET->getLastErrMsg()); \
        return ERR_B2B2C_DBSTORAGE_DBOPR; \
    }\
    oStorage.SetDBOperator(pIDB);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//db初始化
int CCooperatorDBOperator::InitDB(IUserDefineCntl* pCntl)
{
    CDAL_SET->AddCmd("0xA0101801");
    CDAL_SET->AddCmd("0xA0101802");
    CDAL_SET->AddCmd("0xA0111802");
    CDAL_SET->AddCmd("0xA0111801");
    CDAL_SET->AddCmd("0xA0111803");

    if (CDAL_SET->Initialize("/usr/local/c2csvc/global_conf/dal_set.xml"))
    {
        C2C_WW_LOG_ERR(-1, "CDAL_SET->Initialize() fail.");
        return -1;
    }
    C2C_WW_LOG("CDAL_SET->Initialize Ok");

    return 0;
}

/**
*
*   更新【新增和修改】合作伙伴子帐号信息
*
*/
int CCooperatorDBOperator::UpdateCooperatorSubAccount(
                            const CCntlInfo& rCntlInfo,
                            const std::string& strMachineKey,
                            const std::string& strSource,
                            uint32_t dwSceneId,
                            uint32_t dwCooperatorId,
                            const std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo>& vecCooperatorSubAccountDdo,
                            const std::string& strInReserve,
                            std::string& strErrmsg,
                            std::string& strOutReserve
                        )
{
    int iRetCode = 0;
    uint32_t i;
    uint16_t wUseSetId = 0;
    uint8_t cUpateFlag = 0;
    //如果子帐号列表为空则退出
    if( vecCooperatorSubAccountDdo.size() <= 0 )
    {
        return 0;
    }

    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR_SUBACCOUNT;
    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)
    std::stringstream sqlReplace;
    std::stringstream sqlSelect;

    sqlReplace << "REPLACE INTO ";
    sqlReplace << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId,
                        DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR_SUBACCOUNT).c_str();
    sqlReplace << " (Fcooperatorsubaccountid, Fcooperatorid, Fnavid, Fnavname, Fcooperatorsubaccountstate, Fcooperatorprotocolid, "
                   "Fsubaccountproperty, Fsubaccountproperty1, Fcooperatorsubaccountaddtime, Fcooperatorsubaccountlastupdatetime) VALUES ";

    for(i=0; i<vecCooperatorSubAccountDdo.size(); i++)
    {
        //查询记录是否存在
        sqlSelect.str(""); //清除上次sqlSelect
        sqlSelect << "SELECT * FROM ";
        sqlSelect << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId,
                DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR_SUBACCOUNT).c_str();
        sqlSelect << " WHERE Fcooperatorsubaccountid = " << vecCooperatorSubAccountDdo[i].GetCooperatorSubAccountId();
        C2C_WW_LOG_DEBUG("%s", sqlSelect.str().c_str());

        c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sqlSelect.str());
        if(oRs.IsReady() != true) //db操作错误
        {
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sqlSelect.str().c_str());
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                             rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
            return ERR_SUBACCOUNT_SELECT;
        }

        oRs.First();

        if( vecCooperatorSubAccountDdo[i].IsCooperatorSubAccountStateSet())
        {
            cUpateFlag = 1;
            if (oRs.GetRecordCount() == 0) //db查询记录不存在
            {
                //插入新记录
                //数据检查，各项字段均必填，查看记录是否完整
                if( !(vecCooperatorSubAccountDdo[i].IsCooperatorSubAccountIdSet() && vecCooperatorSubAccountDdo[i].IsCooperatorIdSet()
                        && vecCooperatorSubAccountDdo[i].IsNavIdSet() && vecCooperatorSubAccountDdo[i].IsNavNameSet()
                     && vecCooperatorSubAccountDdo[i].IsCooperatorSubAccountStateSet()))
                {
                    oRs.Close();
                    C2C_WW_LOG_ERR(ERR_SUBACCOUNT_ITEM_LACK, "OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u ErrMsg:%s",
                                    rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                                    dwCooperatorId, "新增合作伙伴基本信息时,子帐号信息填写不完整");
                    return ERR_SUBACCOUNT_ITEM_LACK;
                }

                sqlReplace << "(" << vecCooperatorSubAccountDdo[i].GetCooperatorSubAccountId() <<", "
                    << vecCooperatorSubAccountDdo[i].GetCooperatorId() <<", "
                    << vecCooperatorSubAccountDdo[i].GetNavId() <<", "
                    << "'" << oStorage.EscapeString(vecCooperatorSubAccountDdo[i].GetNavName()) <<"', "
                    << (vecCooperatorSubAccountDdo[i].GetCooperatorSubAccountState() + 0) << ", "
                    << vecCooperatorSubAccountDdo[i].GetCooperatorProtocolId() <<", ";
                if(vecCooperatorSubAccountDdo[i].IsBitIncludeSet())
                 {
                     std::bitset<128> bs = vecCooperatorSubAccountDdo[i].GetBitInclude();
                     uint64_t ddwProperty = 0;
                     uint64_t ddwProperty1 = 0;
                     for(size_t i = 0; i < bs.size(); ++i)
                     {
                         if(bs.test(i))
                         {
                             if(i < 64)
                             {
                                 ddwProperty |= ((uint64_t)1 << i);
                             }
                             else
                             {
                                 ddwProperty1 |= ((uint64_t)1 << (i - 64));
                             }
                         }
                     }
                     sqlReplace << ddwProperty << ", ";
                     sqlReplace << ddwProperty1 << ", ";
                 }else{
                     sqlReplace << "0, 0, ";
                 }
                sqlReplace << "now()" <<", ";
                sqlReplace    << "now()" <<")";
                if(i!=vecCooperatorSubAccountDdo.size()-1) sqlReplace  << ", ";
            }
            else
            {
                uint64_t ddwSubaccountProperty = 0;
                uint64_t ddwSubaccountProperty1 = 0;
                ddwSubaccountProperty = (uint64_t)oRs.GetBigUInt("Fsubaccountproperty");
                ddwSubaccountProperty1 = (uint64_t)oRs.GetBigUInt("Fsubaccountproperty1");
                sqlReplace << "( " << vecCooperatorSubAccountDdo[i].GetCooperatorSubAccountId() <<", "
                           << vecCooperatorSubAccountDdo[i].GetCooperatorId() <<", ";
                if(vecCooperatorSubAccountDdo[i].IsNavIdSet())
                {
                   sqlReplace << vecCooperatorSubAccountDdo[i].GetNavId() <<", ";
                }
                else{
                    sqlReplace << (uint32_t)oRs.GetUInt("Fnavid") <<", ";
                }
                if(vecCooperatorSubAccountDdo[i].IsNavNameSet())
                {
                   sqlReplace << "'" << oStorage.EscapeString(vecCooperatorSubAccountDdo[i].GetNavName()) <<"', ";
                }
                else{
                    sqlReplace << "'" << oRs.GetString("Fnavname") <<"', ";
                }
                if(vecCooperatorSubAccountDdo[i].IsCooperatorSubAccountStateSet())
                    sqlReplace << (vecCooperatorSubAccountDdo[i].GetCooperatorSubAccountState() + 0) <<", ";
                else
                    sqlReplace << ((uint8_t)oRs.GetUInt("Fcooperatorsubaccountstate") + 0) <<", ";
                if(vecCooperatorSubAccountDdo[i].IsCooperatorProtocolIdSet())
                    sqlReplace << vecCooperatorSubAccountDdo[i].GetCooperatorProtocolId() <<", ";
                else
                    sqlReplace << (uint32_t)oRs.GetUInt("Fcooperatorprotocolid") <<", ";
                if(vecCooperatorSubAccountDdo[i].IsBitIncludeSet())
                {
                    std::bitset<128> bs = vecCooperatorSubAccountDdo[i].GetBitInclude();
                    uint64_t ddwProperty = 0;
                    uint64_t ddwProperty1 = 0;
                    for(size_t i = 0; i < bs.size(); ++i)
                    {
                        if(bs.test(i))
                        {
                            if(i < 64)
                            {
                                ddwProperty |= ((uint64_t)1 << i);
                            }
                            else
                            {
                                ddwProperty1 |= ((uint64_t)1 << (i - 64));
                            }
                        }
                    }
                    ddwSubaccountProperty = ddwSubaccountProperty | ddwProperty;
                    ddwSubaccountProperty1 = ddwSubaccountProperty1 | ddwProperty1;
                }
                if(vecCooperatorSubAccountDdo[i].IsBitExcludeSet())
                {
                    std::bitset<128> bs = vecCooperatorSubAccountDdo[i].GetBitExclude();
                    uint64_t ddwProperty = 0;
                    uint64_t ddwProperty1 = 0;
                    for(size_t i = 0; i < bs.size(); ++i)
                    {
                        if(bs.test(i))
                        {
                            if(i < 64)
                            {
                                ddwProperty |= ((uint64_t)1 << i);
                            }
                            else
                            {
                                ddwProperty1 |= ((uint64_t)1 << (i - 64));
                            }
                        }
                    }
                    ddwSubaccountProperty = ddwSubaccountProperty & (~ddwProperty);
                    ddwSubaccountProperty1 = ddwSubaccountProperty1 & (~ddwProperty1);
                }
                sqlReplace << ddwSubaccountProperty <<", ";
                sqlReplace << ddwSubaccountProperty1 <<", ";
                sqlReplace << (uint32_t)oRs.GetUInt("Fcooperatorsubaccountaddtime") <<", ";
                sqlReplace << "now()" << " ) ";
                if(i!=vecCooperatorSubAccountDdo.size()-1) sqlReplace  << ", ";
            }
        }
        C2C_WW_LOG_DEBUG("%s", sqlReplace.str().c_str());

        if(cUpateFlag==0)
        {
            C2C_WW_LOG("Call UpdateCooperatorSubAccount ok, no CooperatorSubAccount to update");
            return 0;
        }

        oRs.Close();
    }

    iRetCode = oStorage.Update(sqlReplace.str());
    if(iRetCode!=0)
    {
        //错误日志
        C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sqlReplace.str().c_str());
        C2C_WW_LOG_ERR(ERR_SUBACCOUNT_REPLACE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
        return ERR_SUBACCOUNT_REPLACE;
    }

    return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴基本信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::UpdateCooperatorBaseInfo(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                const b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwRecordCount = 0;
    uint64_t ddwExcludeProperty = 0;
    uint64_t ddwExcludeProperty1 = 0;
    uint64_t ddwIncludeProperty = 0;
    uint64_t ddwIncludeProperty1 = 0;
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
    const std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo>& vecCooperatorSubAccountDdo = oCooperatorBaseInfoDdo.GetCooperatorSubAccountDdo();

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), oCooperatorBaseInfoDdo.GetCooperatorId(), sDbRoleName, sTableBaseName, wUseSetId)
    //查询记录是否存在
    std::stringstream sql; //select 1 from tablename where col = col limit 1;
    sql << "SELECT 1 FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorBaseInfoDdo.GetCooperatorId(),
            DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
    sql << " WHERE Fcooperatorid = " << oCooperatorBaseInfoDdo.GetCooperatorId();
    sql << " LIMIT 1";
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());
    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(oRs.IsReady() != true) //db操作错误
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, oCooperatorBaseInfoDdo.GetCooperatorId());
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    //检查合作伙伴基本信息是否有数据需要更新，如没有则返回
    if( (( oCooperatorBaseInfoDdo.IsCooperatorNameSet()
         || oCooperatorBaseInfoDdo.IsCooperatorDiminutiveSet()
         || oCooperatorBaseInfoDdo.IsCooperatorLegalPersonSet()
         || oCooperatorBaseInfoDdo.IsCooperatorAddressSet()
         || oCooperatorBaseInfoDdo.IsCooperatorPhoneSet()
         || oCooperatorBaseInfoDdo.IsCooperatorFaxSet()
         || oCooperatorBaseInfoDdo.IsCooperatorEmailSet()
         || oCooperatorBaseInfoDdo.IsCooperatorTypeSet()
         || oCooperatorBaseInfoDdo.IsCooperatorStateSet()
         || oCooperatorBaseInfoDdo.IsContractNoSet()
         || oCooperatorBaseInfoDdo.IsOrgIdSet()
         || oCooperatorBaseInfoDdo.IsOrgFullNameSet()
         || oCooperatorBaseInfoDdo.IsCvIdSet()
         || oCooperatorBaseInfoDdo.IsCvNameSet()
         || oCooperatorBaseInfoDdo.IsCooperatorAddrDiminutiveSet()
         || oCooperatorBaseInfoDdo.IsCustomerHotLineSet()
         || oCooperatorBaseInfoDdo.IsBitExcludeSet()
         || oCooperatorBaseInfoDdo.IsBitIncludeSet())))
    {
        if (!oRs.First() || (dwRecordCount =oRs.GetRecordCount()) == 0) //db查询记录不存在
        {
            //插入新记录
            //数据检查，各项字段均必填，查看记录是否完整
            if( !((oCooperatorBaseInfoDdo.IsCooperatorIdSet() && oCooperatorBaseInfoDdo.IsCooperatorNameSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorDiminutiveSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorLegalPersonSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorAddressSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorPhoneSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorEmailSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorTypeSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorStateSet()
                 && oCooperatorBaseInfoDdo.IsContractNoSet()
                 && oCooperatorBaseInfoDdo.IsOrgIdSet()
                 && oCooperatorBaseInfoDdo.IsOrgFullNameSet()
                 && oCooperatorBaseInfoDdo.IsCvIdSet()
                 && oCooperatorBaseInfoDdo.IsCvNameSet()
                 && oCooperatorBaseInfoDdo.IsCooperatorAddrDiminutiveSet()
                 && oCooperatorBaseInfoDdo.IsCustomerHotLineSet())))
            {
                oRs.Close();
                C2C_WW_LOG_ERR(ERR_COOPERATOR_ITEM_LACK, "OpUin:%u MachineKey:%s Source:%s SceneId:%u IsCooperatorIdSet():%u IsCooperatorNameSet:%u "
                                "IsCooperatorLegalPersonSet:%u IsCooperatorAddressSet:%u IsCooperatorPhoneSet:%u IsCooperatorFaxSet:%u "
                                "IsCooperatorEmailSet:%u IsCooperatorTypeSet:%u IsCooperatorStateSet:%u IsContractNoSet:%u "
                                "IsOrgIdSet:%u IsOrgFullNameSet:%u IsCvIdSet:%u IsCvNameSet:%u IsCooperatorAddrDiminutiveSet:%u IsCustomerHotLineSet:%u ErrMsg:%s",
                                rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                                oCooperatorBaseInfoDdo.IsCooperatorIdSet(),
                                oCooperatorBaseInfoDdo.IsCooperatorNameSet(), oCooperatorBaseInfoDdo.IsCooperatorLegalPersonSet(),
                                oCooperatorBaseInfoDdo.IsCooperatorAddressSet(),
                                oCooperatorBaseInfoDdo.IsCooperatorPhoneSet(),
                                oCooperatorBaseInfoDdo.IsCooperatorFaxSet(),
                                 oCooperatorBaseInfoDdo.IsCooperatorEmailSet(),
                                oCooperatorBaseInfoDdo.IsCooperatorTypeSet(), oCooperatorBaseInfoDdo.IsCooperatorStateSet(),
                                oCooperatorBaseInfoDdo.IsContractNoSet(), oCooperatorBaseInfoDdo.IsOrgIdSet(), oCooperatorBaseInfoDdo.IsOrgFullNameSet(),
                                oCooperatorBaseInfoDdo.IsCvIdSet(), oCooperatorBaseInfoDdo.IsCvNameSet(),oCooperatorBaseInfoDdo.IsCooperatorAddrDiminutiveSet(),
                                oCooperatorBaseInfoDdo.IsCustomerHotLineSet(), "新增合作伙伴基本信息时,字段填写不完整");
                return ERR_COOPERATOR_ITEM_LACK; //设置字段不完整返回
            }

            sql.str(""); //清除上次sql
            sql << "INSERT INTO ";
        }
        else
        {
            //记录存在则更新记录
            sql.str(""); //清除上次sql
            sql << "UPDATE ";
        }

        sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorBaseInfoDdo.GetCooperatorId(),
                DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
        sql << " SET ";
        sql << "Fcooperatorid=" << oCooperatorBaseInfoDdo.GetCooperatorId();
        if(oCooperatorBaseInfoDdo.IsCooperatorNameSet())
            sql << ", Fcooperatorname='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorName()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorDiminutiveSet())
            sql << ", Fcooperatordiminutive='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorDiminutive()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorLegalPersonSet())
            sql << ", Fcooperatorlegalperson='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorLegalPerson()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorAddressSet())
            sql << ", Fcooperatoraddress='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorAddress()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorPhoneSet())
            sql << ", Fcooperatorphone='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorPhone()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorFaxSet())
            sql << ", Fcooperatorfax='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorFax()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorEmailSet())
            sql << ", Fcooperatoremail='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorEmail()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorTypeSet())
            sql << ", Fcooperatortype=" << (oCooperatorBaseInfoDdo.GetCooperatorType() + 0);
        if(oCooperatorBaseInfoDdo.IsCooperatorSpidSet())
            sql << ", Fcooperatorspid='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorSpid()) <<"'";
        if(oCooperatorBaseInfoDdo.IsBitIncludeSet())
        {
            std::bitset<128> bs = oCooperatorBaseInfoDdo.GetBitInclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwIncludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwIncludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
            //sql << ", Fcooperatorproperty=Fcooperatorproperty|"          << ddwProperty;
            //sql << ", Fcooperatorproperty1=Fcooperatorproperty1|"          << ddwProperty1;
        }
        if(oCooperatorBaseInfoDdo.IsBitExcludeSet())
        {
            std::bitset<128> bs = oCooperatorBaseInfoDdo.GetBitExclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwExcludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwExcludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
            //sql << ", Fcooperatorproperty=Fcooperatorproperty&" << ~ddwProperty;
            //sql << ", Fcooperatorproperty1=Fcooperatorproperty1&" << ~ddwProperty1;
        }
        sql << ", Fcooperatorproperty=((Fcooperatorproperty|" << ddwIncludeProperty << ")&" << ~ddwExcludeProperty<< ")";
        sql << ", Fcooperatorproperty1=((Fcooperatorproperty1|" << ddwIncludeProperty1 << ")&" << ~ddwExcludeProperty1<< ")";
        if(oCooperatorBaseInfoDdo.IsCooperatorStateSet())
            sql << ", Fcooperatorstate=" << (oCooperatorBaseInfoDdo.GetCooperatorState() + 0);
        if(oCooperatorBaseInfoDdo.IsContractNoSet())
            sql << ", Fcontractno='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetContractNo()) <<"'";
        if(oCooperatorBaseInfoDdo.IsOrgIdSet())
            sql << ", Forgid=" << oCooperatorBaseInfoDdo.GetOrgId();
        if(oCooperatorBaseInfoDdo.IsOrgFullNameSet())
            sql << ", Forgfullname='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetOrgFullName()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCvIdSet())
            sql << ", Fcvid=" << oCooperatorBaseInfoDdo.GetCvId();
        if(oCooperatorBaseInfoDdo.IsCvNameSet())
            sql << ", Fcvname='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCvName()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCooperatorAddrDiminutiveSet())
            sql << ", Fcooperatoraddrdiminutive='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorAddrDiminutive()) <<"'";
        if(oCooperatorBaseInfoDdo.IsCustomerHotLineSet())
            sql << ", Fcustomerhotline='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCustomerHotLine()) <<"'";

		if(oCooperatorBaseInfoDdo.IsIcsonIdSet())
		{
			sql << ", Ficsonid=" << oCooperatorBaseInfoDdo.GetIcsonId();
		}
		if(oCooperatorBaseInfoDdo.IsSellerTypeSet())
		{
			sql << ", Fsellertype=" << oCooperatorBaseInfoDdo.GetSellerType();
		}
		if(oCooperatorBaseInfoDdo.IsCooperatorEnNameSet())
		{
			sql << ", Fcooperatorenname='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorEnName()) << "'";
		}
		if(oCooperatorBaseInfoDdo.IsCooperatorContactPersonSet())
		{
			sql << ", Fcooperatorcontactperson='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorContactPerson()) << "'";
		}
		if(oCooperatorBaseInfoDdo.IsCooperatorAccountSet())
		{
			sql << ", Fcooperatoraccount='" << oStorage.EscapeString(oCooperatorBaseInfoDdo.GetCooperatorAccount()) << "'";
		}
		if(oCooperatorBaseInfoDdo.IsCooperatorAccountTypeSet())
		{
			sql << ", Fcooperatoraccounttype=" << oCooperatorBaseInfoDdo.GetCooperatorAccountType();
		}
        sql << ", Fcooperatorlastupdatetime=" << "now()";
        if(dwRecordCount == 0 ){
            sql << ", Fcooperatoraddtime=" << "now()";
        }else{
            sql << " WHERE Fcooperatorid = " << oCooperatorBaseInfoDdo.GetCooperatorId();
        }
        C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

        iRetCode = oStorage.Update(sql.str());
        if(iRetCode!=0)
        {
            //错误日志
            oRs.Close();
            C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
            C2C_WW_LOG_ERR(ERR_COOPERATOR_UPDATE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                            rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                            oCooperatorBaseInfoDdo.GetCooperatorId());
            return ERR_COOPERATOR_UPDATE;
        }

        iRetCode = UpdateCooperatorSubAccount(rCntlInfo, strMachineKey, strSource, dwSceneId, oCooperatorBaseInfoDdo.GetCooperatorId(),
                                        vecCooperatorSubAccountDdo, strInReserve, strErrmsg, strOutReserve);
    }
    else
    {
        //更新或者插入子帐号表，当不存在合作伙伴信息时，不增加或更新子帐号信息
        if(dwRecordCount > 0)
        {
            iRetCode = UpdateCooperatorSubAccount(rCntlInfo, strMachineKey, strSource, dwSceneId, oCooperatorBaseInfoDdo.GetCooperatorId(),
                                        vecCooperatorSubAccountDdo, strInReserve, strErrmsg, strOutReserve);
        }else{
            if( vecCooperatorSubAccountDdo.size() > 0 ) return ERR_COOPERATOR_NOT_EXIST;
        }
    }

    if(iRetCode!=0)
    {
        oRs.Close();
        C2C_WW_LOG_ERR(iRetCode, "UpdateCooperatorSubAccount failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                        oCooperatorBaseInfoDdo.GetCooperatorId());
        return iRetCode;
    }

    oRs.Close();
    C2C_WW_LOG("%s Finished, CooperatorId:%u", __FUNCTION__, oCooperatorBaseInfoDdo.GetCooperatorId());
    return 0;
}

/**
 *
 * 获取合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param Set licenseType: 许可证类型，为空则为全部许可证列表  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param Vector cooperatorLicenseDdo: 合作伙伴许可证信息     [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::GetCooperatorLicense(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwCooperatorId,
                const std::set<uint8_t >& setLicenseType,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo >& vecCooperatorLicenseDdo,
                std::string& strOutReserve
    )
{
    uint16_t wUseSetId = 0;
    uint32_t dwTime = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
    const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR_LICENSE;
    std::stringstream sql;
    C2C_WW_LOG("GetAReq %s CmdId:%u CooperatorId:%u", __FUNCTION__, rCntlInfo.getCmdId(), dwCooperatorId);
    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

    //查询合作伙伴许可证信息
    sql << "SELECT * FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_COOPERATOR, TABLE_NAME_COOPERATOR_LICENSE).c_str();
    sql << " WHERE Fcooperatorid = " << dwCooperatorId;
    for (std::set<uint8_t>::iterator it = setLicenseType.begin(); it != setLicenseType.end(); it++)
    {
        sql << " AND Flicensetype = " << (*it+0);
    }
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(!oRs.IsReady()) //db操作错误
    {
        oRs.Close();
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
    {
        oRs.Close();
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "QuerySql not exist, "
                        "OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
        return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
    }

    do{
        b2b2c::cooperator::ddo::CCooperatorLicenseDdo oCooperatorLicenseDdo;
        oCooperatorLicenseDdo.SetCooperatorId((uint32_t)dwCooperatorId);
        oCooperatorLicenseDdo.SetLicenseType((uint8_t)oRs.GetUInt("Flicensetype"));
        oCooperatorLicenseDdo.SetLicenseCode(oRs.GetString("Flicensecode")?oRs.GetString("Flicensecode"):"");
        oCooperatorLicenseDdo.SetCooperatorScope(oRs.GetString("Flicensescope")?oRs.GetString("Flicensescope"):"");
        oCooperatorLicenseDdo.SetLicenseBeginDate((uint32_t)oRs.GetUInt("Flicensebegindate"));
        oCooperatorLicenseDdo.SetLicenseEndDate((uint32_t)oRs.GetUInt("Flicenseenddate"));
        dwTime = StrToTime(oRs.GetString("Flicenseaddtime")?oRs.GetString("Flicenseaddtime"):"");
        oCooperatorLicenseDdo.SetLicenseaddtime(dwTime);
        dwTime = StrToTime(oRs.GetString("Flicenselastupdatetime")?oRs.GetString("Flicenselastupdatetime"):"");
        oCooperatorLicenseDdo.SetLicenselastupdatetime(dwTime);
		oCooperatorLicenseDdo.SetPid(oRs.GetUInt("Fpid"));
		oCooperatorLicenseDdo.SetFileUrl(oRs.GetString("Ffileurl")?oRs.GetString("Ffileurl"):"");
        vecCooperatorLicenseDdo.push_back(oCooperatorLicenseDdo);
    }while(oRs.Next());
    oRs.Close();

    return 0;
}

/**
 *
 * 获取合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴基本信息  [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::GetCooperatorBaseInfo(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwCooperatorId,
                const std::string& strInReserve,
                std::string& strErrmsg,
                b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
                std::string& strOutReserve
    )
{
    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwTime = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
    std::stringstream sql;

    //获取合作伙伴子帐号信息
    std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo> vecCooperatorSubAccountDdo;
    iRetCode = GetCooperatorSubAccount(rCntlInfo, strMachineKey, strSource, dwSceneId, ddwCooperatorId,
                                            vecCooperatorSubAccountDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode!=0 && iRetCode!= ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT)
    {
        C2C_WW_LOG_ERR(iRetCode, "GetCooperatorSubAccount failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);
        return iRetCode;
    }
    if(iRetCode!= ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT)
    {
        oCooperatorBaseInfoDdo.SetCooperatorSubAccountDdo(vecCooperatorSubAccountDdo);
    }

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)
    //查询指定合作伙伴基本信息
    sql << "SELECT * FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
    sql << " WHERE Fcooperatorid = " << dwCooperatorId;
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(!oRs.IsReady()) //db操作错误
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    if(!oRs.First() || oRs.GetRecordCount() == 0 ) //无记录
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT,
                        "QuerySql not exist, OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu dwCooperatorId:%u Sql:%s",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId, dwCooperatorId,
                        sql.str().c_str());
        oRs.Close();
        return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
    }

    oCooperatorBaseInfoDdo.SetCooperatorId((uint32_t)dwCooperatorId);
    oCooperatorBaseInfoDdo.SetCooperatorName(oRs.GetString("Fcooperatorname")?oRs.GetString("Fcooperatorname"):"");
    oCooperatorBaseInfoDdo.SetCooperatorDiminutive(oRs.GetString("Fcooperatordiminutive")?oRs.GetString("Fcooperatordiminutive"):"");
    oCooperatorBaseInfoDdo.SetCooperatorLegalPerson(oRs.GetString("Fcooperatorlegalperson")?oRs.GetString("Fcooperatorlegalperson"):"");
    oCooperatorBaseInfoDdo.SetCooperatorAddress(oRs.GetString("Fcooperatoraddress")?oRs.GetString("Fcooperatoraddress"):"");
    oCooperatorBaseInfoDdo.SetCooperatorPhone(oRs.GetString("Fcooperatorphone")?oRs.GetString("Fcooperatorphone"):"");
    oCooperatorBaseInfoDdo.SetCooperatorFax(oRs.GetString("Fcooperatorfax")?oRs.GetString("Fcooperatorfax"):"");
    oCooperatorBaseInfoDdo.SetCooperatorEmail(oRs.GetString("Fcooperatoremail")?oRs.GetString("Fcooperatoremail"):"");
    oCooperatorBaseInfoDdo.SetCooperatorType((uint8_t)oRs.GetUInt("Fcooperatortype"));
    oCooperatorBaseInfoDdo.SetCooperatorSpid(oRs.GetString("Fcooperatorspid")?oRs.GetString("Fcooperatorspid"):"");
    uint64_t ddwProperty = oRs.GetBigUInt("Fcooperatorproperty");
    std::bitset<128> bs(ddwProperty);
    uint64_t ddwProperty1 = oRs.GetBigUInt("Fcooperatorproperty1");
    std::bitset<64> bs1(ddwProperty1);
    for(size_t i = 0; i < bs1.size(); ++i)
    {
        if(bs1.test(i))
        {
            bs.set(i+64);
        }
    }
	oCooperatorBaseInfoDdo.SetCooperatorProperty(bs);
    oCooperatorBaseInfoDdo.SetCooperatorState((uint8_t)oRs.GetUInt("Fcooperatorstate"));
    oCooperatorBaseInfoDdo.SetContractNo(oRs.GetString("Fcontractno")?oRs.GetString("Fcontractno"):"");
    oCooperatorBaseInfoDdo.SetOrgId((uint64_t)oRs.GetBigUInt("Forgid"));
    oCooperatorBaseInfoDdo.SetOrgFullName(oRs.GetString("Forgfullname")?oRs.GetString("Forgfullname"):"");
    oCooperatorBaseInfoDdo.SetCvId((uint64_t)oRs.GetBigUInt("Fcvid"));
    oCooperatorBaseInfoDdo.SetCvName(oRs.GetString("Fcvname")?oRs.GetString("Fcvname"):"");
    dwTime = StrToTime(oRs.GetString("Fcooperatoraddtime")?oRs.GetString("Fcooperatoraddtime"):"");
    oCooperatorBaseInfoDdo.SetCooperatorAddTime(dwTime);
    dwTime = StrToTime(oRs.GetString("Fcooperatorlastupdatetime")?oRs.GetString("Fcooperatorlastupdatetime"):"");
    oCooperatorBaseInfoDdo.SetCooperatorLastUpdateTime(dwTime);
    oCooperatorBaseInfoDdo.SetCooperatorAddrDiminutive(oRs.GetString("Fcooperatoraddrdiminutive")?oRs.GetString("Fcooperatoraddrdiminutive"):"");
    oCooperatorBaseInfoDdo.SetCustomerHotLine(oRs.GetString("Fcustomerhotline")?oRs.GetString("Fcustomerhotline"):"");
	oCooperatorBaseInfoDdo.SetIcsonId(oRs.GetUInt("Ficsonid"));
	oCooperatorBaseInfoDdo.SetSellerType(oRs.GetUInt("Fsellertype"));
	oCooperatorBaseInfoDdo.SetCooperatorEnName(oRs.GetString("Fcooperatorenname")?oRs.GetString("Fcooperatorenname"):"");
	oCooperatorBaseInfoDdo.SetCooperatorContactPerson(oRs.GetString("Fcooperatorcontactperson")?oRs.GetString("Fcooperatorcontactperson"):"");
	oCooperatorBaseInfoDdo.SetCooperatorAccount(oRs.GetString("Fcooperatoraccount")?oRs.GetString("Fcooperatoraccount"):"");
	oCooperatorBaseInfoDdo.SetCooperatorAccountType(oRs.GetUInt("Fcooperatoraccounttype"));
    oRs.Close();

    return 0;
}

/**
*
*   获取合作伙伴子帐号信息
*
*/
int CCooperatorDBOperator::GetCooperatorSubAccount(
                            const CCntlInfo& rCntlInfo,
                            const std::string& strMachineKey,
                            const std::string& strSource,
                            uint32_t dwSceneId,
                            uint64_t ddwCooperatorId,
                            std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo>  &vecCooperatorSubAccountDdo,
                            const std::string& strInReserve,
                            std::string& strErrmsg,
                            std::string& strOutReserve)
{
    uint16_t wUseSetId = 0;
    uint32_t dwTime = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR_SUBACCOUNT;
    std::stringstream sql;

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

    //查询合作伙伴子帐号信息
    sql << "SELECT * FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR_SUBACCOUNT).c_str();
    sql << " WHERE Fcooperatorid = " << dwCooperatorId;
    C2C_WW_LOG_DEBUG("sql:%s", sql.str().c_str());

    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(!oRs.IsReady()) //db操作错误
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u"
                        "ddwCooperatorId:%lu CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                        ddwCooperatorId, dwCooperatorId);
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "QuerySql not exist, OpUin:%u MachineKey:%s "
                "Source:%s SceneId:%u ddwCooperatorId:%lu CooperatorId:%u",
                rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                ddwCooperatorId, dwCooperatorId);
        oRs.Close();
        return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
    }

    do{
        b2b2c::cooperator::ddo::CCooperatorSubAccountDdo oCooperatorSubAccountDdo;
        oCooperatorSubAccountDdo.SetCooperatorSubAccountId((uint64_t)oRs.GetBigUInt("Fcooperatorsubaccountid"));
        oCooperatorSubAccountDdo.SetCooperatorId((uint32_t)oRs.GetUInt("Fcooperatorid"));
        oCooperatorSubAccountDdo.SetCooperatorSubAccountState((uint8_t)oRs.GetUInt("Fcooperatorsubaccountstate"));
        oCooperatorSubAccountDdo.SetCooperatorProtocolId((uint64_t)oRs.GetBigUInt("Fcooperatorprotocolid"));
        uint64_t ddwProperty = oRs.GetBigUInt("Fsubaccountproperty");
        std::bitset<128> bs(ddwProperty);
        uint64_t ddwProperty1 = oRs.GetBigUInt("Fsubaccountproperty1");
        std::bitset<64> bs1(ddwProperty1);
        for(size_t i = 0; i < bs1.size(); ++i)
        {
            if(bs1.test(i))
            {
                bs.set(i+64);
            }
        }
        oCooperatorSubAccountDdo.SetCooperatorSubAccountProperty(bs);
        oCooperatorSubAccountDdo.SetNavId((uint32_t)oRs.GetBigUInt("Fnavid"));
        oCooperatorSubAccountDdo.SetNavName(oRs.GetString("Fnavname")?oRs.GetString("Fnavname"):"");
        dwTime = StrToTime(oRs.GetString("Fcooperatorsubaccountaddtime")?oRs.GetString("Fcooperatorsubaccountaddtime"):"");
        oCooperatorSubAccountDdo.SetCooperatorSubAccountAddTime(dwTime);
        dwTime = StrToTime(oRs.GetString("Fcooperatorsubaccountlastupdatetime")?oRs.GetString("Fcooperatorsubaccountlastupdatetime"):"");
        oCooperatorSubAccountDdo.SetCooperatorSubAccountLastUpdateTime(dwTime);
        vecCooperatorSubAccountDdo.push_back(oCooperatorSubAccountDdo);
    }while(oRs.Next());
    oRs.Close();

    return 0;
}

/**
 *
 * 设置合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorOldPassword: 合作伙伴老密码（三次MD5加密），必填  [in]
 *@param String cooperatorNewPassword: 合作伙伴新密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::SetCooperatorPassWd(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwCooperatorId,
                uint8_t cCheckPwFlag, //0 - 没有检查老密码；1 - 已经检查老密码
                const std::string& strCooperatorOldPassword,
                const std::string& strCooperatorNewPassword,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
    std::string sPassWordInDb;
    std::stringstream sql;

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)
    if(1!=cCheckPwFlag) //没有检查老密码
    {
        //查询记录是否存在
        std::stringstream sql; //select 1 from tablename where col = col limit 1;
        sql << "SELECT Fcooperatorpassword FROM ";
        sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
        sql << " WHERE Fcooperatorid = " << dwCooperatorId;

        C2C_WW_LOG_DEBUG("%s", sql.str().c_str());
        c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
        if(oRs.IsReady() != true) //db操作错误
        {
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s "
                    "SceneId:%u CooperatorId:%u CooperatorOldPassword:%s CooperatorNewPassword:%s",
                    rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                    dwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());
            return ERR_B2B2C_DBSTORAGE_DBOPR;
        }

        if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
        {
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
            C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "QuerySql not exist, OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                    "CooperatorId:%u CooperatorOldPassword:%s CooperatorNewPassword:%s",
                    rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                    dwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());
            oRs.Close();
            return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
        }

        sPassWordInDb = oRs.GetString("Fcooperatorpassword")?oRs.GetString("Fcooperatorpassword"):"";
        if(sPassWordInDb != "" && sPassWordInDb.compare(strCooperatorOldPassword)) //密码验证失败
        {
            return ERR_COOPERATOR_OLD_PASSWORD; //老密码错误
        }
    }

    sql.str(""); //清除上次sql
    sql << "UPDATE ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId,
                        DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
    sql << " SET Fcooperatorpassword='" << oStorage.EscapeString(strCooperatorNewPassword) << "'";
    sql << ", Fcooperatorlastupdatetime=" << "now()";
    sql << " WHERE Fcooperatorid = " <<dwCooperatorId;

    iRetCode = oStorage.Update(sql.str());
    if(iRetCode!=0)
    {
        //错误日志
        C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DB_STORAGE_UPDATE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                "CooperatorId:%u CooperatorOldPassword:%s CooperatorNewPassword:%s",
                rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                dwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());
        return ERR_B2B2C_DB_STORAGE_UPDATE;
    }

    return 0;
}

/**
 *
 * 检查合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorPassword: 合作伙伴密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::CheckCooperatorPassWd(
                            const CCntlInfo& rCntlInfo,
                            const std::string& strMachineKey,
                            const std::string& strSource,
                            uint32_t dwSceneId,
                            uint64_t ddwCooperatorId,
                            const std::string& strCooperatorPassword,
                            const std::string& strInReserve,
                            std::string& strErrmsg,
                            std::string& strOutReserve
    )
{
     uint16_t wUseSetId = 0;
     uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
     const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
     const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
     std::string sPassWordInDb;

     CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

     //查询密码字段
     std::stringstream sql;
     sql << "SELECT Fcooperatorpassword FROM ";
     sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
     sql << " WHERE Fcooperatorid = " << dwCooperatorId;
     C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

     c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
     if(oRs.IsReady() != true) //db操作错误
     {
         C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
         C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, CooperatorId:%u CooperatorPassword:%s",
                         dwCooperatorId, strCooperatorPassword.c_str());
         return ERR_B2B2C_DBSTORAGE_DBOPR;
     }

     if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
     {
         C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
         C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "QuerySql not exist, CooperatorId:%u CooperatorPassword:%s",
                         dwCooperatorId, strCooperatorPassword.c_str());
         oRs.Close();
         return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
     }

     sPassWordInDb = oRs.GetString("Fcooperatorpassword")?oRs.GetString("Fcooperatorpassword"):"";
     if(sPassWordInDb.compare(strCooperatorPassword)) //密码验证失败
     {
         C2C_WW_LOG_ERR(ERR_COOPERATOR_PASSWD_NOT_MATCH, "CooperatorId:%u CooperatorPassword:%s",
                          dwCooperatorId, strCooperatorPassword.c_str());
         return ERR_COOPERATOR_PASSWD_NOT_MATCH; //验证密码失败，密码错误
     }

     return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorLicenseDdo cooperatorLicenseDdo: 合作伙伴许可证信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int CCooperatorDBOperator::UpdateCooperatorLicense(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                const b2b2c::cooperator::ddo::CCooperatorLicenseDdo& oCooperatorLicenseDdo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR_LICENSE;

    //查询记录是否存在
    std::stringstream sql; //select 1 from tablename where col = col limit 1;
    sql << "SELECT 1 FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorLicenseDdo.GetCooperatorId(),
            DB_ROLE_NAME_COOPERATOR, TABLE_NAME_COOPERATOR_LICENSE).c_str();
    sql << " WHERE Fcooperatorid = " << oCooperatorLicenseDdo.GetCooperatorId();
    sql << " LIMIT 1";
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(oRs.IsReady() != true) //db操作错误
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, CooperatorId:%u",
                    oCooperatorLicenseDdo.GetCooperatorId());
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    if (!oRs.First() || oRs.GetRecordCount() == 0) //db查询记录不存在
    {
        //插入新记录
        //数据检查，各项字段均必填，查看记录是否完整
        if(!(oCooperatorLicenseDdo.IsCooperatorIdSet() && oCooperatorLicenseDdo.IsLicenseTypeSet()
            && oCooperatorLicenseDdo.IsLicenseCodeSet()
            && oCooperatorLicenseDdo.IsCooperatorScopeSet()
            && oCooperatorLicenseDdo.IsLicenseBeginDateSet()
            && oCooperatorLicenseDdo.IsLicenseEndDateSet()))
        {
            C2C_WW_LOG_ERR(ERR_COOPERATOR_LICENSE_ITEM_LACK, "CooperatorId:%u ErrMsg:许可证信息字段设置不完整",
                                oCooperatorLicenseDdo.GetCooperatorId());
            return ERR_COOPERATOR_LICENSE_ITEM_LACK; //设置字段不完整返回
        }

        sql.str(""); //清除上次sql
        sql << "INSERT INTO ";
        sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorLicenseDdo.GetCooperatorId(),
                DB_ROLE_NAME_COOPERATOR, TABLE_NAME_COOPERATOR_LICENSE).c_str();
        sql << " (Fcooperatorid, Flicensetype, Flicensecode, Flicensescope, "
               "Flicensebegindate, Flicenseenddate, Flicenseaddtime, Flicenselastupdatetime) VALUES ("
        << oCooperatorLicenseDdo.GetCooperatorId() <<", "
        << (oCooperatorLicenseDdo.GetLicenseType() + 0) <<", "
        << "'" << oStorage.EscapeString(oCooperatorLicenseDdo.GetLicenseCode()) << "', "
        << "'"<< oStorage.EscapeString(oCooperatorLicenseDdo.GetCooperatorScope()) <<"', "
        << oCooperatorLicenseDdo.GetLicenseBeginDate() << ", "
        << oCooperatorLicenseDdo.GetLicenseEndDate() << ", "
        << "now()" <<", "
        << "now()" <<")";
    }
    else
    {
        //记录存在则更新记录
        sql.str(""); //清除上次sql
        sql << "UPDATE ";
        sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorLicenseDdo.GetCooperatorId(),
                DB_ROLE_NAME_COOPERATOR, TABLE_NAME_COOPERATOR_LICENSE).c_str();
        sql << " SET ";
        if(oCooperatorLicenseDdo.IsLicenseTypeSet())
            sql << " Flicensetype=" << (oCooperatorLicenseDdo.GetLicenseType() + 0);
        if(oCooperatorLicenseDdo.IsLicenseCodeSet())
            sql << ", Flicensecode='" << oStorage.EscapeString(oCooperatorLicenseDdo.GetLicenseCode()) <<"'";
        if(oCooperatorLicenseDdo.IsCooperatorScopeSet())
            sql << ", Flicensescope='" << oStorage.EscapeString(oCooperatorLicenseDdo.GetCooperatorScope()) <<"'";
        if(oCooperatorLicenseDdo.IsLicenseBeginDateSet())
            sql << ", Flicensebegindate=" << oCooperatorLicenseDdo.GetLicenseBeginDate();
        if(oCooperatorLicenseDdo.IsLicenseEndDateSet())
           sql << ", Flicenseenddate=" << oCooperatorLicenseDdo.GetLicenseEndDate();
		if(oCooperatorLicenseDdo.IsPidSet())
			sql << ", Fpid=" << oCooperatorLicenseDdo.GetPid();
		if(oCooperatorLicenseDdo.IsFileUrlSet())
			sql << ", Ffileurl='" << oStorage.EscapeString(oCooperatorLicenseDdo.GetFileUrl()) << "'";
        sql << ", Flicenselastupdatetime=" << "now()";
        sql << " WHERE Fcooperatorid = " << oCooperatorLicenseDdo.GetCooperatorId();
    }

    iRetCode = oStorage.Update(sql.str());
    if(iRetCode!=0)
    {
        //错误日志
        C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DB_STORAGE_UPDATE, "ExeSql Failed, CooperatorId:%u", oCooperatorLicenseDdo.GetCooperatorId());
        return ERR_B2B2C_DB_STORAGE_UPDATE;
    }

    return 0;
}

int CCooperatorDBOperator::GetCooperatorKey(
                            const CCntlInfo& rCntlInfo,
                            const std::string& strMachineKey,
                            const std::string& strSource,
                            uint32_t dwSceneId,
                            uint64_t ddwCooperatorId,
                            const std::string& strInReserve,
                            std::string& strErrmsg,
                            std::string& strSCooperatorKey,
                            std::string& strOutReserve)
{
    uint16_t wUseSetId = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
    std::string sPassWordInDb;

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

    //查询密码字段
    std::stringstream sql;
    sql << "SELECT Fcooperatorpassword FROM ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
    sql << " WHERE Fcooperatorid = " << dwCooperatorId;
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

    c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());
    if(oRs.IsReady() != true) //db操作错误
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, CooperatorId:%u", dwCooperatorId);
        return ERR_B2B2C_DBSTORAGE_DBOPR;
    }

    if(!oRs.First() || oRs.GetRecordCount() <= 0) //无记录
    {
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "QuerySql not exist, CooperatorId:%u", dwCooperatorId);
        oRs.Close();
        return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
    }

    sPassWordInDb = oRs.GetString("Fcooperatorpassword")?oRs.GetString("Fcooperatorpassword"):"";
    Gen32StrHashFromStr(sPassWordInDb, strSCooperatorKey);

    return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴基本信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::SetCooperatorPro(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwOption,
                const b2b2c::cooperator::ddo::CCooperatorProDdo& oCooperatorProDdo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint64_t ddwExcludeProperty = 0;
    uint64_t ddwExcludeProperty1 = 0;
    uint64_t ddwIncludeProperty = 0;
    uint64_t ddwIncludeProperty1 = 0;
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;

    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), 0, sDbRoleName, sTableBaseName, wUseSetId)

    //设置合作伙伴属性位
    std::stringstream sql;
    sql << "UPDATE ";
    sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorProDdo.GetCooperatorId(), DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();
    sql << " SET ";
    if(oCooperatorProDdo.IsBitIncludeSet())
    {
        std::bitset<128> bs = oCooperatorProDdo.GetBitInclude();
        for(size_t i = 0; i < bs.size(); ++i)
        {
            if(bs.test(i))
            {
                if(i < 64)
                {
                    ddwIncludeProperty |= ((uint64_t)1 << i);
                }
                else
                {
                    ddwIncludeProperty1 |= ((uint64_t)1 << (i - 64));
                }
            }
        }
    }
    if(oCooperatorProDdo.IsBitExcludeSet())
    {
        std::bitset<128> bs = oCooperatorProDdo.GetBitExclude();
        for(size_t i = 0; i < bs.size(); ++i)
        {
            if(bs.test(i))
            {
                if(i < 64)
                {
                    ddwExcludeProperty |= ((uint64_t)1 << i);
                }
                else
                {
                    ddwExcludeProperty1 |= ((uint64_t)1 << (i - 64));
                }
            }
        }
    }
    sql << " Fcooperatorproperty=((Fcooperatorproperty|" << ddwIncludeProperty << ")&" << ~ddwExcludeProperty<< ")";
    sql << ", Fcooperatorproperty1=((Fcooperatorproperty1|" << ddwIncludeProperty1 << ")&" << ~ddwExcludeProperty1<< ")";
    sql << ", Fcooperatorlastupdatetime=" << "now() WHERE Fcooperatorid = " << oCooperatorProDdo.GetCooperatorId();
    C2C_WW_LOG_DEBUG("%s", sql.str().c_str());

    iRetCode = oStorage.Update(sql.str());
    if(iRetCode!=0)
    {
        //错误日志
        C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
        C2C_WW_LOG_ERR(ERR_COOPERATOR_UPDATE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                        rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,  oCooperatorProDdo.GetCooperatorId());
        return ERR_COOPERATOR_UPDATE;
    }

    C2C_WW_LOG("%s Finished, CooperatorId:%u", __FUNCTION__, oCooperatorProDdo.GetCooperatorId());
    return 0;
}

/**
 *
 * 从管理后台等其他业务同步过来的设置合作伙伴属性位等信息的接口
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t option: 选项,暂未用  [in]
 *@param CooperatorSetDdo cooperatorSetDdo: 合作伙伴属性位设置，包括合作伙伴ID、设置和取消属性值设置的参数（设置和取消的属性位不能冲突）等，必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::SetCooperatorInfo(
                    const CCntlInfo& rCntlInfo,
                         const std::string& strMachineKey,
                         const std::string& strSource,
                         uint32_t dwSceneId,
                         uint64_t ddwOption,
                         const b2b2c::cooperator::ddo::CCooperatorSetDdo& oCooperatorSetDdo,
                         const std::string& strInReserve,
                         std::string& strErrmsg,
                         std::string& strOutReserve
                        )
{
    uint64_t ddwIncludeProperty = 0;
    uint64_t ddwIncludeProperty1 = 0;
    uint64_t ddwExcludeProperty = 0;
    uint64_t ddwExcludeProperty1 = 0;

    uint64_t ddwSubIncludeProperty = 0;
    uint64_t ddwSubIncludeProperty1 = 0;
    uint64_t ddwSubExcludeProperty = 0;
    uint64_t ddwSubExcludeProperty1 = 0;

    uint8_t cTransactionFlag = 0;

    int iRetCode = 0;
    uint16_t wUseSetId = 0;
    std::stringstream sql;
    const std::string sDbRoleName = DB_ROLE_NAME_SELLER;
    const std::string sTableBaseName = TABLE_NAME_COOPERATOR;
    C2C_WW_LOG("GetAReq %s CmdId:%u ",  __FUNCTION__, rCntlInfo.getCmdId());
    CONNECT_WITH_DAL(rCntlInfo.getCmdId(), 0, sDbRoleName, sTableBaseName, wUseSetId)

    if(oCooperatorSetDdo.IsCooperatorProDdoSet() && oCooperatorSetDdo.IsCooperatorSubProDdoSet())
    {
        cTransactionFlag = 1;
        oStorage.BeginTransaction();
    }

    if(oCooperatorSetDdo.IsCooperatorProDdoSet())
    {
        sql.str(""); //清除上次sql
        sql << "UPDATE ";
        sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorSetDdo.GetCooperatorProDdo().GetCooperatorId(), DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR).c_str();

        if(oCooperatorSetDdo.GetCooperatorProDdo().IsBitIncludeSet())
        {
            std::bitset<128> bs = oCooperatorSetDdo.GetCooperatorProDdo().GetBitInclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwIncludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwIncludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
        }

        if(oCooperatorSetDdo.GetCooperatorProDdo().IsBitExcludeSet())
        {
            std::bitset<128> bs = oCooperatorSetDdo.GetCooperatorProDdo().GetBitExclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwExcludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwExcludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
        }

        sql << " Set Fcooperatorproperty=((Fcooperatorproperty|" << ddwIncludeProperty << ")&" << ~ddwExcludeProperty<< "), ";
        sql << " Fcooperatorproperty1=((Fcooperatorproperty1|" << ddwIncludeProperty1 << ")&" << ~ddwExcludeProperty1<< "), ";
        sql << " Fcooperatorlastupdatetime= now() ";
        sql << " WHERE Fcooperatorid=" << oCooperatorSetDdo.GetCooperatorProDdo().GetCooperatorId();
        //C2C_WW_LOG_DEBUG("Sql:%s", sql.str().c_str());
        iRetCode = oStorage.Update(sql.str());
        if(iRetCode!=0)
        {
            //错误日志
            if(cTransactionFlag){oStorage.RollBackTransaction();}
            C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
            C2C_WW_LOG_ERR(ERR_B2B2C_DB_STORAGE_UPDATE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                            rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                            oCooperatorSetDdo.GetCooperatorProDdo().GetCooperatorId());
            return ERR_B2B2C_DB_STORAGE_UPDATE;
        }
    }

    if(oCooperatorSetDdo.IsCooperatorSubProDdoSet())
    {
        sql.str(""); //清除上次sql
        sql << "UPDATE ";
        sql << " " << CDAL_SET->GetTableName(wUseSetId, oCooperatorSetDdo.GetCooperatorSubProDdo().GetCooperatorId(), DB_ROLE_NAME_SELLER, TABLE_NAME_COOPERATOR_SUBACCOUNT).c_str();

        if(oCooperatorSetDdo.GetCooperatorSubProDdo().IsBitIncludeSet())
        {
            std::bitset<128> bs = oCooperatorSetDdo.GetCooperatorSubProDdo().GetBitInclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwSubIncludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwSubIncludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
        }

        if(oCooperatorSetDdo.GetCooperatorSubProDdo().IsBitExcludeSet())
        {
            std::bitset<128> bs = oCooperatorSetDdo.GetCooperatorSubProDdo().GetBitExclude();
            for(size_t i = 0; i < bs.size(); ++i)
            {
                if(bs.test(i))
                {
                    if(i < 64)
                    {
                        ddwSubExcludeProperty |= ((uint64_t)1 << i);
                    }
                    else
                    {
                        ddwSubExcludeProperty1 |= ((uint64_t)1 << (i - 64));
                    }
                }
            }
        }

        sql << " Set Fsubaccountproperty=((Fsubaccountproperty|" << ddwSubIncludeProperty << ")&" << ~ddwSubExcludeProperty<< "), ";
        sql << "Fsubaccountproperty1=((Fsubaccountproperty1|" << ddwSubIncludeProperty1 << ")&" << ~ddwSubExcludeProperty1<< "), ";
        sql << " Fcooperatorsubaccountlastupdatetime = now() ";
        sql << " WHERE Fcooperatorid=" << oCooperatorSetDdo.GetCooperatorSubProDdo().GetCooperatorId();
        //C2C_WW_LOG_DEBUG("Sql:%s", sql.str().c_str());
        iRetCode = oStorage.Update(sql.str());
        if(iRetCode!=0)
        {
            //错误日志
            if(cTransactionFlag){oStorage.RollBackTransaction();}
            C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
            C2C_WW_LOG_ERR(ERR_B2B2C_DB_STORAGE_UPDATE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                            rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                            oCooperatorSetDdo.GetCooperatorSubProDdo().GetCooperatorId());
            return ERR_B2B2C_DB_STORAGE_UPDATE;
        }
    }

    if(cTransactionFlag){oStorage.CommitTransaction();}
    C2C_WW_LOG("SetCooperatorInfo Finished");
    return 0;
}


/**
 *
 * 获取价格告警模版列表
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param Vector CooperatorMonitorModelDdo: 告警模版列表 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  int32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::GetCooperatorMonitorModelList(
  		 const CCntlInfo& rCntlInfo,
  		 const std::string& strMachineKey,
  		 const std::string& strSource,
  		 uint32_t dwSceneId,
  		 uint32_t dwCooperatorId,
  		 const std::string& strInReserve,
  		 std::string& strErrmsg,
  		 std::vector<b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo> & vecCooperatorMonitorModelDdo,
  		 std::string& strOutReserve
  		)
{
	int32_t iRetCode = 0;
	uint16_t wUseSetId = 0;
	const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
	const std::string sTableBaseName = TABLE_NAME_MONITOR_MODEL;

	std::stringstream sql;

	CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

	//查询合作伙伴子帐号信息
	sql << "SELECT Fmodelid,Fcooperatorid,Fmodelname,Fmodelrule,Fmonitortouch,Ftype,Fstate,UNIX_TIMESTAMP(Fmodeladdtime) as Fmodeladdtime,UNIX_TIMESTAMP(Fmodellastupdatetime) as Fmodellastupdatetime FROM ";
	sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_COOPERATOR, sTableBaseName).c_str();
	sql << " WHERE Fcooperatorid = " << dwCooperatorId << " and Fstate != " << (MONITOR_MODEL_STATE_DEL*1);//2为标记删除状态，需要过滤
	C2C_WW_LOG_DEBUG("sql:%s", sql.str().c_str());

	c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());

	if(!oRs.IsReady()) //db操作错误
	{
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,dwCooperatorId);
		return ERR_B2B2C_DBSTORAGE_DBOPR;
	}

	if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
	{
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,dwCooperatorId);
		oRs.Close();
		return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
	}

	//循环取数据
	do{
		b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo oCooperatorMonitorModelDdo;
		oCooperatorMonitorModelDdo.SetModelId((uint32_t)oRs.GetUInt("Fmodelid"));
		oCooperatorMonitorModelDdo.SetCooperatorId((uint32_t)oRs.GetUInt("Fcooperatorid"));
		oCooperatorMonitorModelDdo.SetModelName(oRs.GetString("Fmodelname")?oRs.GetString("Fmodelname"):"");
		oCooperatorMonitorModelDdo.SetModelRule(oRs.GetString("Fmodelrule")?oRs.GetString("Fmodelrule"):"");
		oCooperatorMonitorModelDdo.SetMonitorTouch((uint16_t)oRs.GetUInt("Fmonitortouch"));
		oCooperatorMonitorModelDdo.SetModelType((uint16_t)oRs.GetUInt("Ftype"));
		oCooperatorMonitorModelDdo.SetModelState((uint16_t)oRs.GetUInt("Fstate"));
		oCooperatorMonitorModelDdo.SetModelAddTime((uint32_t)oRs.GetUInt("Fmodeladdtime"));
		oCooperatorMonitorModelDdo.SetModelLastUpdateTime((uint32_t)oRs.GetUInt("Fmodellastupdatetime"));

		vecCooperatorMonitorModelDdo.push_back(oCooperatorMonitorModelDdo);
	}while(oRs.Next());
	oRs.Close();

	return iRetCode;
}


/**
 *
 * 通过模版ID获取告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param CooperatorMonitorModelDdo CooperatorMonitorModelDdo: 告警模版 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  int32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::GetCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;
	uint16_t wUseSetId = 0;
	//uint32_t dwTime = 0;
	const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
	const std::string sTableBaseName = TABLE_NAME_MONITOR_MODEL;

	std::stringstream sql;

	CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

	//查询合作伙伴子帐号信息
	sql << "SELECT Fmodelid,Fcooperatorid,Fmodelname,Fmodelrule,Fmonitortouch,Ftype,Fstate,UNIX_TIMESTAMP(Fmodeladdtime) as Fmodeladdtime,UNIX_TIMESTAMP(Fmodellastupdatetime) as Fmodellastupdatetime FROM ";
	sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_COOPERATOR, sTableBaseName).c_str();
	sql << " WHERE Fmodelid = " << dwModelId << " and Fstate != " << (MONITOR_MODEL_STATE_DEL*1);//2为标记删除状态，需要过滤
	C2C_WW_LOG_DEBUG("sql:%s", sql.str().c_str());

	c2cent::storage::IResultSet& oRs = oStorage.QueryForResultSet(sql.str());

	if(!oRs.IsReady()) //db操作错误
	{
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_DBOPR, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,dwCooperatorId);
		return ERR_B2B2C_DBSTORAGE_DBOPR;
	}

	if(!oRs.First() || oRs.GetRecordCount() == 0) //无记录
	{
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId,dwCooperatorId);
		oRs.Close();
		return ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT;
	}

	//循环取数据
	oCooperatorMonitorModelDdo.SetModelId((uint32_t)oRs.GetUInt("Fmodelid"));
	oCooperatorMonitorModelDdo.SetCooperatorId((uint32_t)oRs.GetUInt("Fcooperatorid"));
	oCooperatorMonitorModelDdo.SetModelName(oRs.GetString("Fmodelname")?oRs.GetString("Fmodelname"):"");
	oCooperatorMonitorModelDdo.SetModelRule(oRs.GetString("Fmodelrule")?oRs.GetString("Fmodelrule"):"");
	oCooperatorMonitorModelDdo.SetMonitorTouch((uint16_t)oRs.GetUInt("Fmonitortouch"));
	oCooperatorMonitorModelDdo.SetModelType((uint16_t)oRs.GetUInt("Ftype"));
	oCooperatorMonitorModelDdo.SetModelState((uint16_t)oRs.GetUInt("Fstate"));
	oCooperatorMonitorModelDdo.SetModelAddTime((uint32_t)oRs.GetUInt("Fmodeladdtime"));
	oCooperatorMonitorModelDdo.SetModelLastUpdateTime((uint32_t)oRs.GetUInt("Fmodellastupdatetime"));
	//关闭
	oRs.Close();

	return iRetCode;
}


/**
 *
 * 新增或者更新告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorMonitorModelDdo CooperatorMonitorModelDdo: 告警模版，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::UpdateCooperatorMonitorModel(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		)
{
	int32_t iRetCode = 0;
	//参数校验
	//模版ID或者合作伙伴ID没设置，都是无法更新的
	if(!oCooperatorMonitorModelDdo.IsModelIdSet() ||
	   !oCooperatorMonitorModelDdo.IsCooperatorIdSet()||
	   oCooperatorMonitorModelDdo.GetModelId()==0 ||
	   oCooperatorMonitorModelDdo.GetCooperatorId()==0
	)
	{
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_UPDATE_NOID, "modelId or cooperatorId not set, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
							rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
		return ERR_MONITORMODEL_UPDATE_NOID;
	}

	//参数校验
	//如果所有值都没设置，说明不需要更新
	if(!oCooperatorMonitorModelDdo.IsModelNameSet() &&
	   !oCooperatorMonitorModelDdo.IsModelRuleSet() &&
	   !oCooperatorMonitorModelDdo.IsMonitorTouchSet() &&
	   !oCooperatorMonitorModelDdo.IsModelTypeSet() &&
	   !oCooperatorMonitorModelDdo.IsModelStateSet()
	)
	{
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_UPDATE_NODATA, "no data for update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
							rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);
		return ERR_MONITORMODEL_UPDATE_NODATA;
	}

	uint32_t dwCooperatorId = oCooperatorMonitorModelDdo.GetCooperatorId();
	uint16_t wUseSetId = 0;
	//uint32_t dwTime = 0;
	const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
	const std::string sTableBaseName = TABLE_NAME_MONITOR_MODEL;

	std::stringstream sql;

	CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

	//插入或者更新一条记录
	sql << " INSERT INTO ";
	sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_COOPERATOR, sTableBaseName).c_str();
	sql << " (Fmodelid,Fcooperatorid,Fmodelname,Fmodelrule,Fmonitortouch,Ftype,Fstate,Fmodeladdtime,Fmodellastupdatetime) ";
	sql << " VALUES( ";
	sql << " " << oCooperatorMonitorModelDdo.GetModelId() << ", ";//int unsigned
	sql << " " << oCooperatorMonitorModelDdo.GetCooperatorId() << ", ";//int unsigned
	sql << "'" << oStorage.EscapeString(oCooperatorMonitorModelDdo.GetModelName()) << "',";//varchar 128
	sql << "'" << oStorage.EscapeString(oCooperatorMonitorModelDdo.GetModelRule()) << "',";//varchar 4096
	sql << " " << oCooperatorMonitorModelDdo.GetMonitorTouch() << ", ";//smallint unsigned
	sql << " " << oCooperatorMonitorModelDdo.GetModelType() << ", ";//smallint unsigned
	sql << " " << oCooperatorMonitorModelDdo.GetModelState() << ", ";//smallint unsigned
	sql << " now(),now()";//datetime datetime
	sql << " ) ON DUPLICATE KEY UPDATE ";
	if(oCooperatorMonitorModelDdo.IsModelNameSet())
	{
		sql << " Fmodelname=VALUES(Fmodelname), ";
	}

	if(oCooperatorMonitorModelDdo.IsModelRuleSet())
	{
		sql << " Fmodelrule=VALUES(Fmodelrule), ";
	}

	if(oCooperatorMonitorModelDdo.IsMonitorTouchSet())
	{
		sql << " Fmonitortouch=VALUES(Fmonitortouch), ";
	}

	if(oCooperatorMonitorModelDdo.IsModelStateSet())
	{
		sql << " Fstate=VALUES(Fstate), ";
	}

	//sql << " Ftype=VALUES(Ftype), ";//update语句这里不会更新类型的，类型一旦存在了 就不会改变了
	sql << " Fmodellastupdatetime=now() ";

	C2C_WW_LOG_DEBUG("sql:%s", sql.str().c_str());//debug

	iRetCode = oStorage.Update(sql.str());

	if(iRetCode!=0)
	{
		//错误日志
		C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_UPDATE_FAIL, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
		return ERR_MONITORMODEL_UPDATE_FAIL;
	}

	//删除操作没有操作到任何一条数据
	if(oStorage.GetAffectedRows()==0)
	{
		//错误日志
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_AFFECT_NONE, "ExeSql Update None, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_AFFECT_NONE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
		return ERR_MONITORMODEL_AFFECT_NONE;
	}

	return iRetCode;
}

/**
 *
 * 删除告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  int32_t : 0(成功) 其它失败
 *
 */
int32_t CCooperatorDBOperator::DeleteCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;
	uint16_t wUseSetId = 0;
	//uint32_t dwTime = 0;
	const std::string sDbRoleName = DB_ROLE_NAME_COOPERATOR;
	const std::string sTableBaseName = TABLE_NAME_MONITOR_MODEL;

	std::stringstream sql;

	CONNECT_WITH_DAL(rCntlInfo.getCmdId(), dwCooperatorId, sDbRoleName, sTableBaseName, wUseSetId)

	//插入或者更新一条记录
	sql << " UPDATE ";
	sql << " " << CDAL_SET->GetTableName(wUseSetId, dwCooperatorId, DB_ROLE_NAME_COOPERATOR, sTableBaseName).c_str();
	sql << " SET Fstate="<< (MONITOR_MODEL_STATE_DEL*1) <<" WHERE ";
	sql << " Fmodelid= " << dwModelId << " and Fcooperatorid= " << dwCooperatorId << " and Ftype!=" << (MONITOR_MODEL_TYPE_SYS*1);//标记删除,非系统模版才行

	C2C_WW_LOG_DEBUG("sql:%s", sql.str().c_str());//debug

	iRetCode = oStorage.Update(sql.str());


	if(iRetCode!=0)
	{
		//错误日志
		C2C_WW_LOG_ERR(iRetCode, "ExeSql Failed, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_DELETE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u ModelId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId,dwModelId);
		return ERR_MONITORMODEL_DELETE;
	}

	//删除操作没有操作到任何一条数据
	if(oStorage.GetAffectedRows()==0)
	{
		//错误日志
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_AFFECT_NONE, "ExeSql Delete None, Sql:%s", sql.str().c_str());
		C2C_WW_LOG_ERR(ERR_MONITORMODEL_AFFECT_NONE, "ExeSql Failed, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u ModelId:%u",
						rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId,dwModelId);
		return ERR_MONITORMODEL_AFFECT_NONE;
	}

	return iRetCode;
}

